<template>
  <div
    class="ui-navmenu-group"
    :class="[{'is-expanded': expanded, 'is-collapse': collapse}, 'ui-navmenu-group--' + type]"
  >
    <div v-if="label" class="ui-navmenu-group__handle" @click="handleHandleClick">
      <span v-if="icon" class="ui-navmenu-group__handle-icon">
        <ui-icon :name="icon" size="20px"></ui-icon>
      </span>
      <span class="ui-navmenu-group__handle-text">
        {{ label }}
      </span>
      <span class="ui-navmenu-group__handle-arrow"></span>
    </div>
    <div class="ui-navmenu-group__content">
      <slot />
    </div>
  </div>
</template>
<script>
export default {
  name: 'UiNavmenuGroup',
  inject: ['UiNavmenu'],
  props: {
    label: {
      type: String,
      default: ''
    },
    icon: {
      type: String
    },
    expanded: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    type () {
      return this.UiNavmenu.type
    },
    collapse () {
      return this.UiNavmenu.collapse
    }
  },
  methods: {
    handleHandleClick () {
      this.$emit('click')
    }
  }
}
</script>
<style lang="less">
.ui-navmenu-group{
  &.is-expanded{
    > .ui-navmenu-group__handle {
      .ui-navmenu-group__handle-arrow{
        transform: translateY(-50%) rotate(180deg);
      }
    }
    > .ui-navmenu-group__content{
      display: block;
    }
  }
  &.is-collapse{
    position: relative;
    .ui-navmenu-group__content{
      position: absolute;
      display: none;
    }
    .ui-navmenu-group__handle{
      padding-left: 20px;
      .ui-navmenu-group__handle-text,
      .ui-navmenu-group__handle-arrow{
        opacity: 0;
      }
    }
  }
}
.ui-navmenu-group__handle{
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 32px;
  line-height: 32px;
  padding: 1px 30px 1px 12px;
  margin: 6px 0;
  text-decoration: none;
  position: relative;
  cursor: pointer;
  transition: all .25s;
}
.ui-navmenu-group__handle-text{
  transition: all .25s;
  opacity: 1;
}
.ui-navmenu-group__handle-icon{
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-right: 6px;
  line-height: 1em;
  background-repeat: no-repeat;
  background-position: 50% 50%;
  background-size: cover;
}
.ui-navmenu-group__handle-arrow{
  display: inline-block;
  width: 20px;
  height: 20px;
  position: relative;
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  transition: all .25s;
  &:after {
    content: '';
    position: absolute;
    top: 4px;
    right: 7px;
    width: 6px;
    height: 6px;
    border: 1px solid transparent;
    border-left: 0;
    border-top: 0;
    transform: rotate(45deg);
  }
}
.ui-navmenu-group {
  .ui-navmenu-item{
    padding-left: 37px;
  }
}
.ui-navmenu-group__content{
  display: none;
}
.ui-navmenu-group--default {
  .ui-navmenu-group__handle{
    border-radius: 5px;
    color: #666;
    &:hover {
      background-color: rgba(0,0,0,.03);
    }
  }
  .ui-navmenu-group__handle-arrow{
    &:after {
      border-color: #999;
    }
  }
}
.ui-navmenu-group--primary {
  .ui-navmenu-group__handle{
    opacity: .7;
    padding-top: 4px;
    padding-bottom: 4px;
    &:hover {
      opacity: 1;
    }
  }
  .ui-navmenu-group__handle-arrow{
    &:after {
      border-color: #fff;
    }
  }
}
</style>
